package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;


import com.zyxx.common.excel.ExcelUtils;
import com.zyxx.common.shiro.SingletonLoginUtils;
import com.zyxx.common.utils.LayTableResult;
import com.zyxx.common.utils.ResponseResult;

import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.zyxx.common.excel.ExcelUtils;


<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

 @Autowired
 private  ${table.serviceName}  ${table.serviceName?uncap_first};


 @ApiOperation(value = "请求用户管理列表页", notes = "请求用户管理列表页")
 @GetMapping("init")
 public String init(Model model) {
 return "portal/${entity?uncap_first}/list";
 }

 @ApiOperation(value = "请求用户管理新增页", notes = "请求用户管理新增页")
 @GetMapping("add")
 public String add(Model model) {
 return "portal/${entity?uncap_first}/add";
 }

 @ApiOperation(value = "请求用户管理编辑页", notes = "请求用户管理编辑页")
 @ApiImplicitParams(@ApiImplicitParam(name = "id", value = "用户id", required = true))
 @GetMapping("update/{id}")
 public String update(@PathVariable Long id, Model model) {
 model.addAttribute("data", ${table.serviceName?uncap_first}.getById(id));

 return "portal/${entity?uncap_first}/update";
 }



 /**
 * 分页列表查询
 * @param ${entity?uncap_first}
 * @param pageNo
 * @param pageSize
 * @param req
 * @return
 */
 @PostMapping("list")
 @ResponseBody
 public LayTableResult list(Integer page, Integer limit, ${entity} ${entity?uncap_first}) {

      return ${table.serviceName?uncap_first}.list(page, limit, ${entity?uncap_first});
 }


 @PostMapping("add")
 @ResponseBody
 public ResponseResult add(@RequestBody ${entity} ${entity?uncap_first}) {
 return ${table.serviceName?uncap_first}.add(${entity?uncap_first});
 }


 @PostMapping("update")
 @ResponseBody
 public ResponseResult update(@RequestBody ${entity} ${entity?uncap_first}) {
 return ${table.serviceName?uncap_first}.update(${entity?uncap_first});
 }

 @ApiOperation(value = "${table.comment!}", notes = "${table.comment!} ")
 @GetMapping(value="/export")
 public ModelAndView  exportxls(@RequestBody ${entity} ${entity?uncap_first}) {

  return Excelutils.export("${table.comment!}信息统计报表",${entity}.class,${table.serviceName?uncap_first}.list(1,Integer.MAX_VALUE,${entity?uncap_first}).getDate());
 }

}
</#if>
